package com.pds.mvc;

import java.io.File;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ServletFinder {
	public static Logger logger = Logger.getLogger(ServletFinder.class);
	private String servletClass;

	public ServletFinder(String xmlFile,String servletName) {
		try {
			File file = new File(xmlFile);
			SAXReader reader = new SAXReader();
			Document document = reader.read(file);
			
			Element root = document.getRootElement();
			
			List nodes = root.elements("servlet");
			Iterator<Element> it = nodes.iterator();
			while(it.hasNext()){
				Element servletElm=it.next();
				if(servletElm.elementText("name").equals(servletName)){
					servletClass=servletElm.elementText("class");
				}
				
			}
		} catch (Exception e) {
			logger.debug("解析XML错误-----------------------------");
			e.printStackTrace();
		}
		
	}
	
	
	public String getServletClass() {
		return servletClass;
	}
	
	
}
